#region "ExceptionWrapper"

/*
 * ####     Developer Name : Wang Yucai
 * 
 * ####     Development Tool : Microsoft VisualStudio 2010 Ultimate Edition
 * 
 * ####     Create Time : 2014/7/7 13:52:30
 * 
 * ####     Namespace : Masterduner.SourceStudio.Practices.DevelopmentLibrary
 * 
 * ####     Type Name : ExceptionWrapper
 * 
 * ####     Full Name : Masterduner.SourceStudio.Practices.DevelopmentLibrary.ExceptionWrapper
 * 
 * ####     Machine Name : GLCHQWYCWINW7
 * 
 * ####     UserName : GUOCOLAND/wangyucai
 * 
 * ####     CLR Version : 4.0.30319.1022
 * 
 * ####     Target Framework Version : 4.0
 */

#endregion

using System;
using System.Runtime.InteropServices;
using Masterduner.SourceStudio.Practices.DevelopmentLibrary.Resources;

namespace Masterduner.SourceStudio.Practices.DevelopmentLibrary
{
    /// <summary>
    /// <para>Masterduner.SourceStudio.Practices.DevelopmentLibrary.ExceptionWrapper</para>
    /// <para>
    /// 定义了开发库的基本异常。
    /// </para>
    /// </summary>
    /// <remarks>
    /// <para>Target Framework Version : 4.0</para>
    /// </remarks>
    [Serializable]
    public class ExceptionWrapper : Exception, IExceptionWrapper, _Exception
    {
        private string _exceptionCode;
        private string _exceptionMessage;

        #region SetExceptionCode
        /// <summary>
        /// 设置异常代码。
        /// </summary>
        /// <param name="code">异常代码。</param>
        protected virtual void SetExceptionCode(string code)
        {
            this._exceptionCode = code;
        }
        #endregion

        #region SetExceptionMessage
        /// <summary>
        /// 设置异常信息。
        /// </summary>
        /// <param name="message">异常信息。</param>
        protected virtual void SetExceptionMessage(string message)
        {
            ExceptionWrapperMessageGenerateTemplate generator = new ExceptionWrapperMessageGenerateTemplate()
            {
                ExceptionCode = this._exceptionCode,
                Message = message,
                MethodName = base.TargetSite.Name,
                TypeName = base.Source,
                StackTrace = base.StackTrace
            };
            this._exceptionMessage = generator.TransformText();
        }
        #endregion

        #region Constructor

        /// <summary>
        /// <para>构造函数：</para>
        /// <para>初始化一个<see cref="ExceptionWrapper" />对象实例。</para>
        /// </summary>
        /// <param name="exceptionCode">开发库定义的异常代码。</param>
        /// <param name="exceptionMessage">异常信息。</param>
        /// <param name="innerException">引发了此次异常的<see cref="Exception"/>对象实例。</param>
        public ExceptionWrapper(string exceptionCode, string exceptionMessage, Exception innerException)
            : base(exceptionMessage, innerException)
        {
            this.SetExceptionCode(exceptionCode);
            this.SetExceptionMessage(exceptionMessage);
        }

        /// <summary>
        /// <para>构造函数：</para>
        /// <para>初始化一个<see cref="ExceptionWrapper" />对象实例。</para>
        /// </summary>
        /// <param name="exceptionMessage">异常信息。</param>
        /// <param name="innerException">引发了此次异常的<see cref="Exception"/>对象实例。</param>
        public ExceptionWrapper(string exceptionMessage, Exception innerException)
            : this("MDSS::DEVLIB::00000000", exceptionMessage, innerException)
        {
        }

        /// <summary>
        /// <para>构造函数：</para>
        /// <para>初始化一个<see cref="ExceptionWrapper" />对象实例。</para>
        /// </summary>
        /// <param name="exceptionMessage">异常信息。</param>
        public ExceptionWrapper(string exceptionMessage)
            : this(exceptionMessage, null)
        {
        }

        /// <summary>
        /// <para>构造函数：</para>
        /// <para>初始化一个<see cref="ExceptionWrapper" />对象实例。</para>
        /// </summary>
        /// <param name="innerException">引发了此次异常的<see cref="Exception"/>对象实例。</param>
        public ExceptionWrapper(Exception innerException)
            : this(ExceptionMessageCollections.ExceptionBase)
        {
        }

        /// <summary>
        /// <para>构造函数：</para>
        /// <para>初始化一个<see cref="ExceptionWrapper" />对象实例。</para>
        /// </summary>
        public ExceptionWrapper()
            : this("MDSS::DEVLIB::00000000", ExceptionMessageCollections.ExceptionBase, null)
        {
        }

        #endregion

        #region IExceptionWrapper Members

        #region ExceptionCode
        /// <summary>
        /// 获取异常代码。
        /// </summary>
        public virtual string ExceptionCode
        {
            get { return this._exceptionCode; }
        }
        #endregion

        #region ExceptionMessage
        /// <summary>
        /// 获取异常信息。
        /// </summary>
        public virtual string ExceptionMessage
        {
            get { return this._exceptionMessage; }
        }
        #endregion

        #endregion
    }
}

#region README

/*
 * ####     ©2014 Wang Yucai
 * 
 * ####     Contact me
 *                  
 *                  E-mail : Masterduner@Yeah.net
 *                  Mobile : 13621384677
 *                  QQ : 180261899
 */

#endregion